package backtracking;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class lc77 {
    List<List<Integer>> result=new ArrayList<>();
    LinkedList<Integer> path=new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
backtrace(n,k,1);
return result;
    }
    void backtrace(int n, int k,int startIndex){
        //递归终止条件
        if(path.size()==k){
            result.add(path);
            return;
        }
        for (int i = startIndex; i <n - (k - path.size()) ; i++) {
            path.add(i);
            backtrace(n,k,i+1);
            path.removeLast();
        }
    }
}
